# 安装
 if [[ -z "$(docker images -q docker.elastic.co/elasticsearch/elasticsearch:7.14.0 2> /dev/null)" ]]; then
    docker pull docker.elastic.co/elasticsearch/elasticsearch:7.14.0
 else
    echo "elasticsearch installed"
  fi
#	运行
  if [[ -z "$(docker ps -aqf "name=es-pattern")" ]]; then
    mkdir -p /opt/elasticsearch/data /opt/elasticsearch/data1 /opt/elasticsearch/datasingle /opt/elasticsearch/logs /opt/elasticsearch/plugins
    chmod 777 /opt/elasticsearch/data /opt/elasticsearch/data1 /opt/elasticsearch/logs /opt/elasticsearch/datasingle /opt/elasticsearch/plugins
    #集群和单机启动任选其一
      ##单机启动
       docker run --name es-pattern -p 22220:9200 -p 9300:9300 \
       --add-host=project-pattern:192.168.0.101 \
       -e discovery.type="single-node" -e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
       -e TAKE_FILE_OWNERSHIP=true -e bootstrap.memory_lock=true \
       --privileged=true --restart=always \
       -v /opt/elasticsearch/datasingle:/usr/share/elasticsearch/data \
       -v /opt/elasticsearch/logs:/usr/share/elasticsearch/logs \
       -v /opt/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d docker.elastic.co/elasticsearch/elasticsearch:7.14.0

      ##集群启动
        #win10 docker:
          #wsl -d docker-desktop
          #sysctl -w vm.max_map_count=262144
        #linux:
          #sysctl -w vm.max_map_count=262144
      #cp /mnt/e/pattern/.environment/init/docker/es/docker-compose.yml /opt/elasticsearch/
      #cd  /opt/elasticsearch/
      #docker-compose up -d

      # 进入容器
      #docker exec -it es01 bash
      #docker exec -it es02 bash
  else
        echo "es-pattern running"
  fi

  #es配置文件添加  xpack.security.enabled: false
